import React,{useState,useRef} from 'react'
import Child4 from '../components/Child4'

export default function UseRef() {


    const [msg, setMsg] = useState("");

    const child4 = useRef();//声明名称



  return (
    <div>
        <button onClick={()=>{
            child4.current.setMsg("来自爸爸的爱");
        }}>设置子组件的内容</button>
        UseRef
        显示子组件的值{msg}
        <button onClick={()=>{
           setMsg(child4.current.getMsg());

        }}>我要获取子组件的内容</button>

        <Child4 setMsg={setMsg} ref={child4}></Child4>
    </div>
  )
}
